﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common/taglibs.jsp"%>
<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>出货管理-新建出货单</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<%@ include file="../common/config.jsp"%>
<%@ include file="../common/validate.jsp"%>
<%@ include file="../common/autocomplete.jsp"%>
<script type="text/javascript" src="js/calendar/WdatePicker.js" ></script>
<script type="text/javascript">
var productNamesIndex = 0;
function addProduct() {
	productNamesIndex++;
	var productTable = $("#productList");
	productTable.find("tr").last().before(
	        '<tr class="odd">'
	          +'<td class="font11">'
	          +'<s:textfield id="productNames-' + productNamesIndex + '" name="productNames" size="30" cssClass="{required:true,maxlength:60}"/>'
	          +'<s:hidden name="productIds" />'
	          +'</td>'
	          +'<td><s:textfield name="productNums" size="10" cssClass="{required:true,maxlength:10,number:true}"/></td>'
	          +'<td><input type="button" value="删除" class="input1" onclick="deleteProduct(this)" /></td>'
	          +'</tr>');
	initProductAutoSelected(productNamesIndex);
}
function deleteProduct(button) {
	$(button).parent().parent().remove();
}

function initProductAutoSelected(id) {
	$("#productNames-" + id).each(function(i) {
		$(this).autocomplete("queryProductNames.action", {
			width: 150,
			max: 10,
			autoFill: false,
			dataType: "json",
			parse: function(data) {
				var parsed = [];
				var rows = data.productList;
				for (var i=0; i < rows.length; i++) {
					var row = rows[i];
					if (row) {
						parsed[parsed.length] = {
							data: row,
							value: row[0],
							result: row[1]//最终选择后显示的内容
						};
					}
				}
				return parsed;
			},
			formatItem: function(row, i, max) {
				return row[1] + " " + row[2];//列表中显示的值
			}
		}).result(function(e, row) {
			$(e.target).next().val(row[0]);
		});
	});
}

$(document).ready(function() {
	$("#addOrder").validate();
	$("#order_customName").autocomplete("queryCustomerNames.action", {
		width: 150,
		max: 10,
		autoFill: false,
		dataType: "json",
		parse: function(data) {
			var parsed = [];
			var rows = data.customerList;
			for (var i=0; i < rows.length; i++) {
				var row = rows[i];
				if (row) {
					parsed[parsed.length] = {
						data: row,
						value: row[0],
						result: "" + row[2] + row[1]//最终选择后显示的内容
					};
				}
			}
			return parsed;
		},
		formatItem: function(row, i, max) {
			return "" + row[2] + row[1];//列表中显示的值
		}
	}).result(function(e, row) {
		//alert(row[0]);//最终选择的ID
		$(e.target).next().val(row[0]);
	});
	
	$("input[name=productNames]").each(function(i) {
		$(this).autocomplete("queryProductNames.action", {
			width: 150,
			max: 10,
			autoFill: false,
			dataType: "json",
			parse: function(data) {
				var parsed = [];
				var rows = data.productList;
				for (var i=0; i < rows.length; i++) {
					var row = rows[i];
					if (row) {
						parsed[parsed.length] = {
							data: row,
							value: row[0],
							result: row[1]//最终选择后显示的内容
						};
					}
				}
				return parsed;
			},
			formatItem: function(row, i, max) {
				return row[1] + " " + row[2];//列表中显示的值
			}
		}).result(function(e, row) {
			$(e.target).next().val(row[0]);
		});
	});
});
</script>
</HEAD>
<BODY>
     <s:form action="addOrder" name="order">
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">出货管理</span>
			&nbsp;<img src="images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">修改出货单</span></td>
		  </tr>
		</table>
      </div>
     <div class="main_1">
       <table width="99%" border="0" cellpadding="5" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td align="left" class="Blue14" bgcolor="#FAFAFA" colspan="2">出货单信息</td>
         </tr>
         <tr>
		    <td width="19%" bgcolor="#FAFAFA" align="right"><strong>创建日期</strong></td>
		    <td width="81%" bgcolor="#FAFAFA"><input type="text" name="order.createDate" readonly="true" size="10" value='<%=com.javaeye.chenweihuacwh.util.DateUtils.dateToString("yyyy-MM-dd")%>' /></td>
		 </tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>客户名称</strong></td>
	      <td bgcolor="#FAFAFA">
			<s:textfield id="order_customName" name="order.customName" size="30" cssClass="{required:true,maxlength:60}"/>
			<s:hidden id="order_customId" name="order.customId" />
			<span class="red-text1">*</span>
		  </td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>订单号</strong></td>
	      <td bgcolor="#FAFAFA">
		    <s:textfield name="order.contractNo" size="20" cssClass="{required:true,maxlength:20}"/>
	        <span class="red-text1">*</span>
	      </td>
		</tr>
         <tr>
		    <td bgcolor="#FAFAFA" align="right"><strong>预出货日期</strong></td>
		    <td bgcolor="#FAFAFA">
				<s:textfield name="order.expectOutDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true"
					 size="10" cssClass="{required:true}"/><span class="red-text1">*</span>
			</td>
		 </tr>
       </table>
     </div>
     <div class="clear"></div>
	 <div class="main_1">
       <table width="99%" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a" id="productList">
        <tr class="ksglxx2bg">
          <th width="35%" >产品名称</th>
		  <th width="20%" align="left">数量</th>
		  <th align="left">&nbsp;</th>
		</tr>
		<s:iterator value="order.orderDetails" id="detail">
        <tr class="odd">
          <td class="font11">
		       <s:textfield name="productNames" size="30" cssClass="{required:true,maxlength:60}"/>
		       <s:hidden name="productIds" />
          </td>
          <td><s:textfield name="productNums" size="10" cssClass="{required:true,maxlength:10,number:true}"/></td>
          <td></td>
	    </tr>
	    </s:iterator>
        <tr>
         <td colspan="3" align="left" valign="top">
           <input type="button" value="添加" class="input1" onclick="addProduct()" />
         </td>
        </tr>
       </table>
      </div>
     <div class="clear"></div>
	 <div class="main_1">
		<table width="98%" border="0" cellpadding="5" cellspacing="0" class="gr-text1">
		   <tr>
			 <td width="45%" align="right">
			   <s:submit value="保存" cssClass="input1" />&nbsp;&nbsp;
			   <input type="button" value="关闭" class="input1" /></td>
			 <td width="55%" align="left"></td>
		   </tr>
	   </table>
	</div>
	<div class="clear"></div>
	</s:form>
</BODY></HTML>
